//
//  IMPersonalBaseInfoView.m
//  Btpin
//
//  Created by Vic on 2019/4/23.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "IMPersonalBaseInfoView.h"

@interface IMPersonalBaseInfoView ()
{
    UIImageView *headerImgView;
    UILabel *nameLbl;
    UILabel *baseInfoLbl;
    UILabel *intentionLbl;
    UILabel *wageLbl;
}
@end

@implementation IMPersonalBaseInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
    headerImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(20*Scale, 15*Scale, 50*Scale, 50*Scale) imageName:@"header_bg"];
    headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    headerImgView.layer.cornerRadius = 25*Scale;
    headerImgView.layer.masksToBounds = YES;
    headerImgView.userInteractionEnabled = NO;
    [self addSubview:headerImgView];
    
    nameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(headerImgView)+10*Scale, 10*Scale, 100, 30*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    nameLbl.font = FontBold(Font_18);
    [self addSubview:nameLbl];
    
    baseInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(nameLbl), 10*Scale, 200, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_14];
    [self addSubview:baseInfoLbl];
    
    intentionLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(nameLbl), EndY(nameLbl), WIDTH-100*Scale, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:intentionLbl];
    
    wageLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(nameLbl), EndY(intentionLbl), WIDTH-100*Scale, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_14];
    [self addSubview:wageLbl];
}
- (void)reloadDataModel:(IMPersonalBaseInfoModel *)model {
    if (model.avatar && model.avatar.length) {
        [headerImgView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"header_bg"]];
    } else {
        headerImgView.image = [UIImage imageNamed:@"header_bg"];
    }
    
    CGFloat nameWidth = [UIToolsControl textWidth:model.name size:CGSizeMake(MAXFLOAT, 30*Scale) font:Font_18]+10*Scale;
    nameLbl.frame = CGRectMake(EndX(headerImgView)+10*Scale, 10*Scale, nameWidth, 30*Scale);
    nameLbl.text = model.name?model.name:@"";
    
    baseInfoLbl.frame = CGRectMake(EndX(nameLbl), 10*Scale, 200, 25*Scale);
    baseInfoLbl.text = [NSString stringWithFormat:@"%@ | %@ | %@", model.sex_cn?model.sex_cn:@"", model.age?model.age:@"", model.education_cn?model.education_cn:@""];
    
    NSString *ssstr = model.intention_jobs;
    NSString *intention1 = [NSString stringWithFormat:@"意向职位：%@", ssstr];
    NSString *intention2 = @"意向职位：";
    NSMutableAttributedString *intentionAtt = [[NSMutableAttributedString alloc] initWithString:intention1];
    [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_15), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_333333} range:NSMakeRange(0, intention1.length)];
    [intentionAtt addAttributes:@{NSFontAttributeName:Font(Font_13), NSForegroundColorAttributeName:THEMECOLOR_OF_TEXT_666666} range:NSMakeRange(0, intention2.length)];
    intentionLbl.attributedText = intentionAtt;
    
    NSString *workInfo1 = [NSString stringWithFormat:@"期望薪资：%@", model.wage_cn?model.wage_cn:@""];
    NSString *workInfo2 = @"期望薪资：";
    NSMutableAttributedString *workAtt = [[NSMutableAttributedString alloc] initWithString:workInfo1];
    [workAtt addAttribute:NSForegroundColorAttributeName value:THEMECOLOR_OF_RED range:NSMakeRange(0, workInfo1.length)];
    [workAtt addAttribute:NSForegroundColorAttributeName value:THEMECOLOR_OF_TEXT_666666 range:NSMakeRange(0, workInfo2.length)];
    wageLbl.attributedText = workAtt;
}

@end
